package com.homedo.odin.solution.service;

import com.homedo.core.common.base.service.BaseService;
import com.homedo.odin.solution.dao.CommonTypeDataMapper;
import com.homedo.odin.solution.enumcode.basic.CommonTypeDataEnum;
import com.homedo.odin.solution.model.entity.CommonTypeData;
import java.util.HashMap;
import java.util.List;
import org.springframework.stereotype.Service;

/**
 * <p> 基础类型数据表 服务实现类 </p>
 *
 * @author HarveyDing
 * @since 2018-03-08
 */
@Service
public class CommonTypeDataServiceImpl extends BaseService<CommonTypeDataMapper, CommonTypeData> {

    public HashMap<String, String> getDataById(int key) {
        List<CommonTypeData> childDataMapById = baseMapper.getChildDataMapById(key);

        HashMap<String, String> map = new HashMap<String, String>();
        for (CommonTypeData commonTypeData : childDataMapById) {
            map.put(commonTypeData.getId() + "", commonTypeData.getName());
        }
        return map;
    }

    public CommonTypeData getCommonTypeDataById(Integer id) {
        return baseMapper.getCommonTypeDataById(id);
    }

    public List<CommonTypeData> querySpecificationclassifyList(Integer parentId) {
        return baseMapper.querySpecificationclassifyList(parentId);
    }

    public List<CommonTypeData> queryDataByName(String name, Integer parentId) {
        return baseMapper.queryDataByName(name, parentId);
    }

    public Integer addCommonTypeData(CommonTypeData addcommonTypeData) {
        baseMapper.addCommonTypeData(addcommonTypeData);
        return addcommonTypeData.getId();
    }

    public void updateCommonTypeData(CommonTypeData addcommonTypeData) {
        baseMapper.updateById(addcommonTypeData);
    }

    public List<CommonTypeData> queryChildNodeById(Integer id) {
        return baseMapper.queryChildNodeById(id);
    }

    public void deleteCommonDataById(CommonTypeData commonTypeData) {
        baseMapper.deleteById(commonTypeData);
    }

    public Integer editCommonDataById(Integer id, Integer sort, String name) {
        return baseMapper.editCommonDataById(id, sort, name);
    }

    /**
     * 根据父节点批量修改是否高亮
     */
    public void updateCommonDataNoHighlightByParentId(Integer id, Integer lighlight) {
        baseMapper.updateCommonDataNoHighlightByParentId(id, lighlight);
    }

    public void updateCommonDataNoHighlightById(Integer id, Integer lighlight) {
        baseMapper.updateCommonDataNoHighlightById(id, lighlight);
    }

    public List<CommonTypeData> getChildDataMapById(int id) {
        return baseMapper.getChildDataMapById(id);
    }


    public List<CommonTypeData> queryChildNodeBy(Integer parentId, Integer highlight) {
        return baseMapper.queryChildNodeBy(parentId, highlight);
    }

    public CommonTypeData queryLateCommonTypeData() {
        int[] ids = new int[]{CommonTypeDataEnum.JZYT.getDbValue(), CommonTypeDataEnum.YJXTSX.getDbValue()};
        return baseMapper.queryLateCommonTypeData(ids);
    }
}
